import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
    {
    path: '/',
    name: 'Home',
    component: () => import('@/views/Home')
  },
  {
    path: '/addCoupon',
    name: 'addCoupon',
    component: () => import('@/views/coupon/AddCoupon'),
    meta: {
      title: '发布优惠券',
      requireAuth: true
    }
  },
  {
    path: '/couponList',
    name: 'couponList',
    component: () => import('@/views/coupon/CouponList'),
    meta: {
      title: '优惠券列表',
      requireAuth: true
    }
  },
  {
    path: '/orderList',
    name: 'orderList',
    component: () => import('@/views/order/OrderList'),
    meta: {
      title: '订单列表',
      requireAuth: true
    }
  },
  {
    path: '/goodsList',
    name: 'goodsList',
    component: () => import('@/views/goods/GoodsList'),
    meta: {
      title: '已上架商品',
      requireAuth: true
    }
  },
  {
    path: '/unstoreGoodsList',
    name: 'unstoreGoodsList',
    component: () => import('@/views/goods/UnstoreGoodsList'),
    meta: {
      title: '可上架商品',
      requireAuth: true
    }
  },

  {
    path: '/register',
    name: 'register',
    component: () => import('@/views/auth/Register'),
    meta: {
      title: '注册'
    }
  },
  // 登录
  {
    name: 'login',
    path: '/login',
    component: () => import('@/views/auth/Login'),
    meta: {
      title: '登录'
    }
  },
  // 用户主页
  {
    name: 'user',
    path: '/member/home/:userIdStr',
    component: () => import('@/views/user/Profile'),
    meta: {
      title: '用户主页',
      requireAuth: true
    }
  },
  // 用户设置
  {
    name: 'user-setting',
    path: '/member/setting/:userIdStr',
    component: () => import('@/views/user/Setting'),
    meta: {
      title: '设置',
      requireAuth: true
    }
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/error/404'),
    meta: {
      title: '404-NotFound'
    }
  },
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }

]


const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


const router = new VueRouter({
  routes
})

export default router
